package com.jt.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component//将对象交给spring容器管理
public class MyMetaObjectHandler implements MetaObjectHandler {
    //完成新增入库操作 create/update
    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        this.setFieldValByName("created", date,metaObject);
        this.setFieldValByName("updated",date,metaObject);
    }
    //完成更改操作 update
    @Override
    public void updateFill(MetaObject metaObject) {
    this.setFieldValByName("updated",new Date(),metaObject);
    }
}
